package com.qf.xml;

import com.qf.web.interceptors.LoginInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration

//<context:component-scan base-package="com.qf.web"/>
@ComponentScan("com.qf.web")

//<mvc:annotation-driven/>
@EnableWebMvc
public class SpringMVCConfig implements WebMvcConfigurer {

    /*
            <mvc:interceptors>
                <mvc:interceptor>
                    <mvc:mapping path="/account/**"/>
                    <bean class="com.qf.web.interceptors.LoginInterceptor"/>
                </mvc:interceptor>
            </mvc:interceptors>
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/account/**");
//                .excludePathPatterns()
    }

    /*
            <mvc:resources mapping="/**" location="/"/>
            <mvc:resources mapping="/js/**" location="/js/"/>
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("/");
        registry.addResourceHandler("/js/**").addResourceLocations("/js/");
    }

//    @Override
//    public void configureViewResolvers(ViewResolverRegistry registry) {
//        InternalResourceViewResolver vr = new InternalResourceViewResolver();
//        vr.setSuffix();
//        vr.setSuffix();
//        registry.viewResolver(vr);
//    }
}
